export const req = (reqUrl, { reqData = {}, isToken = false, method = 'GET' }) => {
  const data = {
    appkey: 'U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=',
    tokenString: localStorage.getItem('TOKEN'),
    ...reqData
  }
  if (!isToken) delete data['tokenString']
  const url = `http://www.kangliuyong.com:10002/${reqUrl}`
  return new Promise((resovle, reject) => {
    const loading = uni.showLoading({
      title: "正在请求服务器数据..."
    })
    uni.request({
      url,
      data,
      method,
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8' // 默认值
      },
      success: (res) => {
        if (res['data']['code'] === 700) {
          return uni.showModal({
            title: "提示",
            content: "登录失效，请重新登录",
            success: (res) => {
              if (res.confirm) {
                uni.navigateTo({
                  url: '/pages/login/login'
                })
              }
            }
          })
        }
        resovle(res)
      },
      fail(err) {
        reject(err)
      },
      complete() {
        uni.hideLoading(loading);
      }
    });
  })
}
